package com.yyy.gui.pannel;

import com.yyy.gui.listener.ToolBarListener;
import com.yyy.util.CenterPanel;
import com.yyy.util.GUIUtil;

import javax.swing.*;
import java.awt.*;

/**
 * @Author：yyy
 * @Package：com.yyy.gui.pannel
 * @Project：HuTuBiill
 * @name：MainPanel
 * @Date：2024/11/7 22:06
 * @Filename：MainPanel
 */
public class MainPanel extends JPanel {
    //设置单例模式
    public static MainPanel instance =new MainPanel();
    //设置页面标题头
    public JToolBar tb=new JToolBar();
    //消费一览
    public JButton bspend=new JButton();
    //记一笔
    public JButton bRecord=new JButton();
    //消费分类
    public JButton bCategory=new JButton();
    //月消费报表
    public JButton bReport=new JButton();
    //设置
    public JButton bConfig=new JButton();
    //备份
    public JButton bBackUp=new JButton();
    //恢复
    public JButton bRecover=new JButton();

    public CenterPanel workingPanel;

    //构造方法
    private MainPanel(){
        //为按钮设置名称及背景图片
        GUIUtil.setImageIcon(bspend,"home.png","消费一览");
        GUIUtil.setImageIcon(bRecord,"record.png","记一笔");
        GUIUtil.setImageIcon(bCategory,"category2.png","消费分类");
        GUIUtil.setImageIcon(bReport,"report.png","月消费报表");
        GUIUtil.setImageIcon(bConfig,"config.png","设置");
        GUIUtil.setImageIcon(bBackUp,"backup.png","备份");
        GUIUtil.setImageIcon(bRecover,"restore.png","恢复");

        tb.add(bspend);
        tb.add(bRecord);
        tb.add(bCategory);
        tb.add(bReport);
        tb.add(bConfig);
        tb.add(bBackUp);
        tb.add(bRecover);
        tb.setFloatable(false);
        workingPanel=new CenterPanel(0.8);
        setLayout(new BorderLayout());
        add(tb,BorderLayout.NORTH);
        add(workingPanel,BorderLayout.CENTER);
        addListener();
    }

    public  void addListener(){
        ToolBarListener listener=new ToolBarListener();
        bspend.addActionListener(listener);
        bRecord.addActionListener(listener);
        bCategory.addActionListener(listener);
        bReport.addActionListener(listener);
        bConfig.addActionListener(listener);
        bBackUp.addActionListener(listener);
        bRecover.addActionListener(listener);
    }

    public static void main(String[] args) {
        GUIUtil.showPanel(instance,1);

    }







}
